-
Notifications
You must be signed in to change notification settings - Fork 546
[CoreCLR] link app native runtime/library statically #9938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
e21e634
to
4e02da2
Compare
e15ccf6
to
9026080
Compare
4aff532
to
0b7bb8c
Compare
96d8326
to
39031e6
Compare
7cdfb21
to
86691d0
Compare
Context: #9938 PR #9938 is an attempt to build `libnet-android.Debug.so` and `libnet-android.Release.so` so that CoreCLR is *statically linked* in to `libnet-android*.so`. This reduces the number of native libraries that must be placed into the `.apk`, and allows the `.apk` to be smaller, as the native linker can remove unused code. *Note*: CoreCLR is ***not*** yet statically linked into `libnet-android*.so`. This is *preliminary* work to support that. This iteration of static linking also requires that *all* symbols be resolvable, by requiring `lld --no-undefined` by default. This in turn requires that we ship *copies* of `libc.so` et al, so that *all* symbols needed by `libnet-android*.so` can be resolved, including those from the Android NDK. Update `build-tools/xaprepare` to extract required native libraries from the NDK, and add those to the .NET for Android Workload packs. Update `Xamarin.Android.Build.Tasks.dll` to cleanup and refactor `ld` invocation, so that `libnet-android*.so` is built with `ld --no-undefined`. This makes it easier to maintain and update the linker code in the future, as well as ensures that we use consistent linking flags across the board. Updates the LLVM IR code generator bits, also extracted from #9938, which aren't strictly related to native linking, but they are placed here in order to make #9938 smaller.
96649e1
to
75e6902
Compare
29ac51a
to
bfc4af0
Compare
9327572
to
3ba61c3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces support for statically linking the .NET native runtime (CoreCLR/Mono) into Android applications by adding new MSBuild tasks, target definitions, and code paths to generate and preserve P/Invoke tables.
- Adds a new
LinkNativeRuntime
task to perform native runtime linking per ABI. - Extends existing code generators (
GenerateNativeMarshalMethodSources
,GenerateJavaStubs
, etc.) with anEnableNativeRuntimeLinking
flag and P/Invoke preservation logic. - Updates MSBuild targets and
xaprepare
scripts to include native runtime assets and configuration properties.
Reviewed Changes
Copilot reviewed 42 out of 42 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
src/Xamarin.Android.Build.Tasks/Tasks/PrepareAbiItems.cs | Added a new mode branch for runtime linking. |
src/Xamarin.Android.Build.Tasks/Tasks/LinkNativeRuntime.cs | Introduced the LinkNativeRuntime AsyncTask. |
src/Xamarin.Android.Build.Tasks/Tasks/GenerateNativeMarshalMethodSources.cs | Added EnableNativeRuntimeLinking path. |
src/Xamarin.Android.Build.Tasks/Tasks/GenerateMainAndroidManifest.cs | Exposed EnableNativeRuntimeLinking property. |
Configuration.props | Defined shared _MonoRuntimeFlavorDirName and _CLRRuntimeFlavorDirName and duplicated _RuntimeRedistDirName . |
Comments suppressed due to low confidence (2)
src/Xamarin.Android.Build.Tasks/Tasks/PrepareAbiItems.cs:57
- The mode string "runtime_linking" does not match the constant name "pinvoke_preserve". Consider renaming one of them for consistency (e.g., use "pinvoke_preserve" as the mode or rename the constant to "runtime_linking").
} else if (String.Compare ("runtime_linking", Mode, StringComparison.OrdinalIgnoreCase) == 0) {
src/Xamarin.Android.Build.Tasks/Tasks/GenerateMainAndroidManifest.cs:28
- This property is declared but not referenced within this task. Remove it or implement its intended behavior to avoid dead code.
public bool EnableNativeRuntimeLinking { get; set; }
src/Xamarin.Android.Build.Tasks/Tasks/GenerateNativeMarshalMethodSources.cs
Show resolved
Hide resolved
ee55bab
to
e0093df
Compare
No description provided.